﻿
Imports OpenFlashChart
Imports System.Data.OleDb
Partial Public Class GeneratesChartTakingData
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.CacheControl = "no-cache"
        Dim Chart As New Graph

        Dim CD As OpenFlashChart.Charts.ChartData

        CD = New OpenFlashChart.Charts.Bar3D(45, "#6F71DF", "#Bar", 4)


        Dim SqlQRY As String = "SELECT PetDetailsQuery.TagName, Count(*) AS TagCount FROM(PetDetailsQuery) GROUP BY PetDetailsQuery.TagName;"

        Dim con As New OleDbConnection(ConfigurationManager.ConnectionStrings("PetsConnectionString").ToString())

        con.Open()
        Dim cmd As New OleDbCommand(SqlQRY, con)
        Dim dr = cmd.ExecuteReader()

        Dim tagHash As New Hashtable
        Dim MAXval As Integer = 0
        Dim MINval As Integer = 0
        If dr.HasRows() Then
            While dr.Read()

                Chart.LabelsX.Add(dr("TagName"))
                CD.Data.Add(CInt(dr("TagCount")))
                If MINval = 0 Then MINval = CInt(dr("TagCount"))
                If MINval > CInt(dr("TagCount")) Then MINval = CInt(dr("TagCount"))
                If MAXval < CInt(dr("TagCount")) Then MAXval = CInt(dr("TagCount"))
            End While
        End If
        Chart.MaxY = MAXval

        Chart.Data.Add(CD)

        Response.Write(Chart.ToString())
    End Sub

End Class